package cn.ty.znsz.menu;

import com.jfinal.aop.Before;
import com.jfinal.aop.Inject;
import com.jfinal.core.Controller;
import com.jfinal.core.Path;
import com.jfinal.kit.Ret;
import com.jfinal.plugin.activerecord.Page;

import cn.ty.znsz.common.interceptor.PostInterceptor;
import cn.ty.znsz.common.model.SysMenu;
import cn.ty.znsz.user.UserService;

@Path(value = "/menu")
public class MenuController extends Controller{
	
	@Inject
	MenuService ms;	
	@Inject 
	UserService us;
	
	/**
	 * 首页
	 */
	public void index() {
		String cookie=getCookie("jznsz");
		//查询菜单权限
		Ret ret=us.getMenuPoint(getParaToInt("id"),cookie);
		setAttr("powers", ret.get("data"));
		render("index.html");
	}
	/**
	 * 首页分页
	 */
	public void paginate() {
		Page<SysMenu> page=ms.paginate(getParaToInt("pageNumber"), getParaToInt("pageSize"),getPara("menuName"));
		renderJson(Ret.create().set("msg", "操作成功").set("code", 0).set("count", page.getTotalRow()).set("data", page.getList()));
	}
	/**
	 * 跳转新增页
	 */
	public void menuAdd() {
		render("menuAdd.html");
	}
	/**
	 * 菜单保存
	 */
	@Before(PostInterceptor.class)
	public void menuSave() {
		SysMenu data=getModel(SysMenu.class, "data");
		Ret ret=ms.menuSave(data);
		renderJson(ret);
	}
	/**
	 * 跳转编辑页
	 */
	public void menuEdit() {
		render("menuEdit.html");
	}
	/**
	 * 菜单修改
	 */
	@Before(PostInterceptor.class)
	public void menuUpdate() {
		SysMenu data=getModel(SysMenu.class, "data");
		Ret ret=ms.menuUpdate(data,getParaToInt("id"));
		renderJson(ret);
	}
	/**
	 * 菜单删除
	 */
	@Before(PostInterceptor.class)
	public void menuDel() {
		Ret ret=ms.menuDel(getParaToInt("id"));
		renderJson(ret);
	}
}
